package step1_homework4_03;

import java.io.*;

public class CopyFile {                                                  //实现文件的复制
        public static void Copy(String path1,String path2){
            BufferedReader br=null;           //创建BufferedReader和BufferedWrite类型的对象，并与磁盘中相应文件关联
            BufferedWriter bw=null;
            try {
                br=new BufferedReader(new FileReader(path1));
                bw=new BufferedWriter(new FileWriter(path2));
            } catch (IOException e) {
                e.printStackTrace();
            }
            String str=null;
            try {
                while ((str=br.readLine())!=null){               //不断的从输入流中读取一行行字符串并写到输出流中
                    bw.write(str);
                    bw.newLine();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }finally {
                try {
                    if (null!=bw){
                        bw.close();
                    }
                    if (null!=br){
                        br.close();
                    }
                    ;
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

        }

}
